<UserControl x:Class="WPFPhysics1.World"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
		xmlns:local="clr-namespace:WPFPhysics1"
		Name="world">

	<UserControl.Resources>

		<DataTemplate DataType="{x:Type local:VehicleBody}">
			<Canvas>
				<Polygon Points="{Binding Points}">
					<Polygon.RenderTransform>
						<MatrixTransform Matrix="{Binding DisplayMatrix}"/>
					</Polygon.RenderTransform>
					<Polygon.Fill>
						<ImageBrush ImageSource="CarBody.png"/>
					</Polygon.Fill>
				</Polygon>
				<ItemsControl ItemsSource="{Binding Tires}">
					<ItemsControl.ItemsPanel>
						<ItemsPanelTemplate>
							<Canvas/>
						</ItemsPanelTemplate>
					</ItemsControl.ItemsPanel>
				</ItemsControl>
			</Canvas>
		</DataTemplate>

		<DataTemplate DataType="{x:Type local:Tire}">
			<Ellipse Width="{Binding Diameter}" Height="{Binding Diameter}" RenderTransformOrigin="0.5, 0.5">
				<Ellipse.RenderTransform>
					<MatrixTransform Matrix="{Binding DisplayMatrix}"/>
				</Ellipse.RenderTransform>
				<Ellipse.Fill>
					<ImageBrush ImageSource="WheelImage3.png" />
				</Ellipse.Fill>
			</Ellipse>
		</DataTemplate>

		<DataTemplate DataType="{x:Type local:PolygonBody}">
			<Polygon Points="{Binding Points}" Fill="#80808000" Stroke="#80000000" StrokeThickness="0.01">
				<Polygon.RenderTransform>
					<MatrixTransform Matrix="{Binding DisplayMatrix}"/>
				</Polygon.RenderTransform>
			</Polygon>
		</DataTemplate>

		<DataTemplate DataType="{x:Type local:EllipseBody}">
			<Ellipse Width="{Binding Width}" Height="{Binding Height}" Stroke="#80000000" StrokeThickness="0.01"  RenderTransformOrigin="0.5, 0.5">
				<Ellipse.RenderTransform>
					<MatrixTransform Matrix="{Binding DisplayMatrix}"/>
				</Ellipse.RenderTransform>
				<Ellipse.Fill>
					<LinearGradientBrush StartPoint="0,0.5" EndPoint="1,0.5">
						<GradientStop Color="#800000FF" Offset="0"/>
						<GradientStop Color="#800000FF" Offset="0.5"/>
						<GradientStop Color="#8000FF00" Offset="0.5"/>
						<GradientStop Color="#8000FF00" Offset="1"/>
					</LinearGradientBrush>
				</Ellipse.Fill>
			</Ellipse>
		</DataTemplate>

		<DataTemplate DataType="{x:Type local:RectangleBody}">
			<Rectangle Width="{Binding Width}" Height="{Binding Height}" Fill="#80FF0000" Stroke="#80000000" StrokeThickness="0.01" RenderTransformOrigin="0.5, 0.5">
				<Rectangle.RenderTransform>
					<MatrixTransform Matrix="{Binding DisplayMatrix}"/>
				</Rectangle.RenderTransform>
			</Rectangle>
		</DataTemplate>

		<DataTemplate DataType="{x:Type local:StaticRectangleBody}">
		  <Rectangle Width="{Binding Width}" Height="{Binding Height}" Fill="Brown" RenderTransformOrigin="0.5, 0.5">
			  <Rectangle.RenderTransform>
				  <MatrixTransform Matrix="{Binding DisplayMatrix}"/>
			  </Rectangle.RenderTransform>
        <Rectangle.BitmapEffect>
          <OuterGlowBitmapEffect GlowColor="Cyan" GlowSize="0"/>
        </Rectangle.BitmapEffect>
        <Rectangle.Triggers>
          <EventTrigger RoutedEvent="Mouse.MouseEnter">
            <EventTrigger.Actions>
              <BeginStoryboard>
                <Storyboard>
                  <DoubleAnimation Storyboard.TargetProperty="BitmapEffect.GlowSize" Duration="0:0:0.2" To="0.5"/>
                </Storyboard>
              </BeginStoryboard>
            </EventTrigger.Actions>
          </EventTrigger>
          <EventTrigger RoutedEvent="Mouse.MouseLeave">
            <EventTrigger.Actions>
              <BeginStoryboard>
                <Storyboard>
                  <DoubleAnimation Storyboard.TargetProperty="BitmapEffect.GlowSize" Duration="0:0:0.2" To="0"/>
                </Storyboard>
              </BeginStoryboard>
            </EventTrigger.Actions>
          </EventTrigger>
        </Rectangle.Triggers>
      </Rectangle>
		</DataTemplate>

	</UserControl.Resources>

	<ItemsControl ItemsSource="{Binding}">
		<ItemsControl.ItemsPanel>
			<ItemsPanelTemplate>
				<Canvas/>
			</ItemsPanelTemplate>
		</ItemsControl.ItemsPanel>
		<ItemsControl.RenderTransform>
			<MatrixTransform Matrix="{Binding ElementName=world, Path=ScaleTransform}"/>
		</ItemsControl.RenderTransform>
	</ItemsControl>

</UserControl>
